import { connect } from 'react-redux'
import React, { Component } from 'react'
interface IProps {
    history: any
    addV:any
}
interface IState {
    getTitle: string,
    get1: string,
    get2: string,
    get3: string,
    get4: string,
    ste: Object,
    id:number
}
class ChangePassword extends Component<IProps, IState> {
    state = {
        getTitle: '',
        get1: '',
        get2: '',
        get3: '',
        get4: '',
        ste: {},
        id:0
    }
    getT = (e: any) => {
        this.setState({
            getTitle: e.target.value
        })
    }
    getC1 = (e: any) => {
        this.setState({
            get1: e.target.value
        })
    }
    getC2 = (e: any) => {
        this.setState({
            get2: e.target.value
        })
    }
    getC3 = (e: any) => {
        this.setState({
            get3: e.target.value
        })
    }
    getC4 = (e: any) => {
        this.setState({
            get4: e.target.value
        })
    }
    addOK=()=>{
        let { getTitle, get1, get2, get3, get4,id } = this.state
        if(getTitle&& get1&& get2&& get3&& get4){
            this.setState({
            ste:{
                "select": [
                    {
                        "title": get1,
                        "size": 0
                    },
                    {
                        "title": get2,
                        "size": 0
                    },
                    {
                        "title": get3,
                        "size": 0
                    },
                    {
                        "title":get4,
                        "size": 0
                    }
                ],
                "info": null,
                "title": getTitle,
                "id": id++,
                "endtime": "2020-02-01T06:40:00.000Z",
                "uid": "fimegt0j3b",
                "createVoteUserInfo": {
                    "phone": "18701553442",
                    "username": "yihang",
                    "id": "fimegt0j3b"
                },
                "size": 0,
                "selected": 1
            }
        })
        console.log(this.state.ste);
        setTimeout(()=>{
            this.props.addV(this.state.ste)
        this.props.history.push('/home')
            
        },0)
        }else{
            alert("请输入内容")
        }
    }
    render() {
        let { getTitle, get1, get2, get3, get4 } = this.state
        return (
            <div className="addList">
                <header><span onClick={() => {
                    this.props.history.go(-1)
                }}>返回</span></header>
                <p className="p1">
                    添加标题：<input type="text" placeholder="请输入标题" value={getTitle} onChange={(e) => {
                        this.getT(e)
                    }} />
                </p>
                <ul>
                    <li>选项1：<input type="text" value={get1} onChange={(e) => {
                        this.getC1(e)
                    }} /></li>
                    <li>选项2：<input type="text" value={get2} onChange={(e) => {
                        this.getC2(e)
                    }} /></li>
                    <li>选项3：<input type="text" value={get3} onChange={(e) => {
                        this.getC3(e)
                    }} /></li>
                    <li>选项4：<input type="text" value={get4} onChange={(e) => {
                        this.getC4(e)
                    }} /></li>
                </ul>
                <button onClick={()=>{
                    this.addOK()
                }}>添加</button>
            </div>
        )
    }
}
const state = (state: any) => {
    return {
       
    }
}
const dispatch = (dispatch: any) => {
    return {
       addV(str:any){
           dispatch({type:"GET_V",str})
       }
    }
}
export default connect(state, dispatch)(ChangePassword) 

